home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / mced-1.0.lha / CEDScripts / MakeComment.ced next >
Encoding:
Text File  |  1992-09-02  |  4.6 KB  |  155 lines

  1. /*
  2. **    MakeComment.ced
  3. **    
  4. **    $VER: MakeComment.ced 1.1 (14.1.95)
  5. **    
  6. **    This script makes comment boxes like this. It makes provision for various
  7. **    languages and has two box-styles. These properties are specified by using
  8. **    parameters.
  9. **    To comment a block, mark it and call this macro. To comment a line,
  10. **    just call the macro.
  11. **    See docs for more details.
  12. **    
  13. **    This script requires CygnusEd Professional v3.5 (or later) to run.
  14. **    
  15. **    Copyright © 1993-95 Michael Letowski
  16. */
  17.  
  18. /* Get host */
  19. PARSE SOURCE com res called resolved ext host .
  20. IF host="REXX" THEN                                                /* From command line */
  21.     ADDRESS "rexx_ced"                                            /* Talk to default ced */
  22.  
  23. OPTIONS RESULTS                                                        /* Hear it from CED */
  24. ARG commentType language .                                /* How to comment? */
  25.  
  26. /* Specify known languages here: */
  27.  
  28. Len.=2;                    Beg.="/*";            End.="*/";            Fill.="*"            /* Defaults */
  29. Len.pas=2;            Beg.pas="(*";        End.pas="*)";        Fill.pas="*"
  30. Len.p=2;                Beg.p="{*";            End.p="*}";            Fill.p="*"
  31. Len.cpp=2;            Beg.cpp="//";        End.cpp="//";        Fill.cpp="/"
  32. Len.hpp=2;            Beg.hpp="//";        End.hpp="//";        Fill.hpp="/"
  33. Len.ada=2;            Beg.ada="--";        End.ada="--";        Fill.ada="-"
  34. Len.bas=1;            Beg.bas="'";        End.bas="'";        Fill.bas="'"
  35. Len.asm=1;            Beg.asm="*";        End.asm="*";        Fill.asm="*"
  36. Len.s=1;                Beg.s=";";            End.s=";";            Fill.s= ";"
  37. Len.mak=1;            Beg.mak="#";        End.mak="#";        Fill.mak= "#"
  38.  
  39. LF="0A"X
  40. TAB="09"X
  41. Ops=0                                                                            /* Number of ops for undo */
  42.  
  43. IF language="" THEN                                                /* Language not explicitly given */
  44. DO
  45.     'Status RESTNAME'                                                /* Get file name */
  46.     PARSE UPPER VAR RESULT 1 "." language
  47. END
  48.  
  49. 'Status RIGHTBORDER'                                            /* Get right border value */
  50. Border=RESULT                                                            /* And store it */
  51.  
  52. 'DM "Commenting..."'
  53.  
  54. 'Cut block'                                                                /* Cut marked block */
  55. IF RESULT THEN                                                        /* There is a marked block */
  56.     CALL CommentBlock                                                /* Comment as block */
  57. ELSE                                                                            /* No marked block */
  58.     CALL CommentLine                                                /* Comment as line */
  59.  
  60. CALL SetClip(UndoClipName(),Ops)                    /* Set data for Undo.ced */
  61.  
  62. 'DM'                                                                            /* Restore status line */
  63.  
  64. EXIT                                                                            /* Finished */
  65.  
  66. CommentBlock:
  67.     'Status BLOCKBUFFER'                                        /* Get buffer */
  68.     ToComment=RESULT                                                /* And store it */
  69.     IF Length(ToComment)=0 THEN                            /* Nothing to comment */
  70.     DO
  71.         'Okay1' "No area marked."
  72.         RETURN
  73.     END
  74.     Ops=Ops+1
  75.     Lines=Length(ToComment)-Length(Compress(ToComment,LF))
  76.                                                                                     /* Get number of lines in buffer */
  77.     IF Lines=0 THEN                                                    /* This is part of a line */
  78.     DO
  79.         ToComment=ToComment||LF                                /* Change it to line */
  80.         Lines=1
  81.     END
  82.     ToInsert=""                                                            /* Initialize block */
  83.     DO FOR Lines                                                        /* For each line... */
  84.         LFPos=Pos(LF,ToComment)                                /* Find end of a line */
  85.         CurrLine=SubStr(ToComment,1,LFPos-1)
  86.                                                                                     /* Cut the line */
  87.         ToComment=DelStr(ToComment,1,LFPos)
  88.                                                                                     /* And remove it from block */
  89.         ToInsert=ToInsert||MakeLine(CurrLine)
  90.                                                                                     /* Append comments */
  91.     END
  92.     'Text' MakeFirstLine()||ToInsert||MakeLastLine()
  93.                                                                                     /* Insert back to CED */
  94.     Ops=Ops+RESULT
  95. RETURN
  96.  
  97. CommentLine:
  98.     'Delete Line'                                                        /* Delete current line */
  99.     Ops=Ops+RESULT
  100.     'Status DELETELINEBUFFER'                                /* Get it line */
  101.     ToComment=Compress(RESULT,LF)                        /* And save it without LFs */
  102.     'Text' MakeFirstLine()||MakeLine(ToComment)||MakeLastLine()
  103.                                                                                     /* Insert to CED */
  104.     Ops=Ops+RESULT
  105. RETURN
  106.  
  107. MakeLine:
  108.     PARSE ARG cL
  109.     SELECT
  110.         WHEN Abbrev("SHORT",Upper(commentType)) THEN
  111.             cL=Copies(Fill.language,Len.language)||TAB||cL||LF
  112.         WHEN Abbrev("LONG",Upper(commentType)) THEN
  113.         DO
  114.             cL=Translate(cL," ",TAB)    /* Change tabs to spaces */
  115.             IF Length(cL)<=Border-2*Len.language THEN
  116.                                                                 /* Line short enough */
  117.                 cL=CENTER(cl,Border-2*Len.language)
  118.                                                                 /* Center line */
  119.             cL=Beg.language||cL||End.language||LF
  120.         END
  121.         OTHERWISE
  122.             cL=Copies(Fill.language,Len.language)||TAB||cL||LF
  123.     END
  124. RETURN cL
  125.  
  126. MakeFirstLine:
  127.     SELECT
  128.         WHEN Abbrev("SHORT",Upper(commentType)) THEN    /* Short comment */
  129.             cL=Beg.language||LF
  130.         WHEN Abbrev("LONG",Upper(commentType)) THEN        /* Full line comment */
  131.             cL=Beg.language||Copies(Fill.language,Border-4)||End.language||LF
  132.         OTHERWISE
  133.             cL=Beg.language||LF
  134.     END
  135. RETURN cL
  136.  
  137. MakeLastLine:
  138.     SELECT
  139.         WHEN Abbrev("SHORT",Upper(commentType)) THEN
  140.             cL=End.language||LF
  141.         WHEN Abbrev("LONG",Upper(commentType)) THEN
  142.             cL=Beg.language||Copies(Fill.language,Border-4)||End.language||LF
  143.         OTHERWISE
  144.             cL=End.language||LF
  145.     END
  146. RETURN cL
  147.  
  148. Extension:
  149.     PARSE ARG name "." ext
  150. RETURN ext
  151.  
  152. UndoClipName:
  153.     'Status FILEMEM'                                                /* Get address of current file */
  154. RETURN "CEDUndo."Right(D2X(RESULT),8,"0")    /* Prepare unique name */
  155.